import {
  axios
} from '@/utils/request'
// 车型列表
function getCarModelList (params) {
  return axios({
    url: '/vehicle-service/model/v2/page',
    method: 'get',
    params
  })
}
// 车型列表导出
function exportCarModelList (params) {
  return axios({
    url: '/vehicle-service/model/v2/export',
    method: 'get',
    params: params,
    responseType: 'blob'
  })
}
function importCarModelList (params) {
  return axios({
    url: '/vehicle-service/import/model',
    method: 'post',
    data: params
  })
}
function importCarModelListTemplate () {
  return axios({
    url: '/vehicle-service/import/template/model',
    method: 'get',
    responseType: 'blob'
  })
}
function importTemplate (code) {
  return axios({
    url: '/vehicle-service/import/template/' + code,
    method: 'get',
    responseType: 'blob'
  })
}
// 所有车型
function getMyAllModel (params) {
  if(!params || !params.pageSize){
    params.pageSize = 1000;
  }
  return axios({
    url: '/vehicle-service/model/select',
    method: 'get',
    params
  })
}
// 删除车型
function deleteCarModel (param) {
  return axios({
    url: '/vehicle-service/model/v2',
    method: 'delete',
    data: param
  })
}
// 新建车型
function addModel (item) {
  return axios({
    url: '/vehicle-service/model/v2',
    method: 'post',
    data: item
  })
}
// 编辑车型
function editModel (item) {
  return axios({
    url: '/vehicle-service/model/v2',
    method: 'put',
    data: item
  })
}
// 编辑车型ECU 配置
function editModelEcuConfig (item) {
  return axios({
    url: '/vehicle-service/model/v2/ecu/config',
    method: 'put',
    data: item
  })
}
// 删除车型ECU 配置
function delModelEcuConfig (id) {
  return axios({
    url: '/vehicle-service/model/v2/ecu/config/' + id,
    method: 'delete',
  })
}
// 获取车型ECU 配置
function getModelEcuConfig (modelId) {
  return axios({
    url: '/vehicle-service/model/v2/ecu/config?modelId='+modelId,
    method: 'get',
  })
}

// 获取车型详情
function getModelDetail (params) {
  return axios({
    url: '/vehicle-service/model/info',
    method: 'get',
    params
  })
}
// 获取配置车型详情
function getConfigModelDetail (params) {
  return axios({
    url: '/vehicle-service/model/v2/info/' + params.id,
    method: 'get',
    params
  })
}

// 所有车型代码名称下拉框
function getMyAllModelCode (params) {
  if(!params || !params.pageSize){
    !params && (params = {});
    params.pageSize = 1000;
  }
  return axios({
    url: '/vehicle-service/model/select/code',
    method: 'get',
    params
  })
}
// 获取车型的ECU配置
function getConfigEcuList (params) {
  return axios({
    url: '/vehicle-service/model/ecu',
    method: 'get',
    params
  })
}
// 修改配置ecu
function putConfigEcu (data) {
  return axios({
    url: '/vehicle-service/model/ecu',
    method: 'put',
    data
  })
}

export default {
  getCarModelList,
  getMyAllModel,
  deleteCarModel: deleteCarModel,
  addModel: addModel,
  editModel: editModel,
  getModelDetail : getModelDetail,
  getConfigModelDetail : getConfigModelDetail,
  getMyAllModelCode : getMyAllModelCode,
  exportCarModelList : exportCarModelList,
  importCarModelList : importCarModelList,
  importCarModelListTemplate : importCarModelListTemplate,
  importTemplate : importTemplate,
  editModelEcuConfig : editModelEcuConfig,
  delModelEcuConfig : delModelEcuConfig,
  getModelEcuConfig : getModelEcuConfig,
  getConfigEcuList,
  putConfigEcu
}
